'use strict';
const db = uniCloud.database();

exports.main = async (event, context) => {
  const { name, contact, content, type } = event;
  
  // 数据验证
  if (!content || content.length < 5) {
    return {
      code: 400,
      message: '反馈内容不能少于5个字符'
    };
  }

  try {
    const collection = db.collection('feedback');
    const result = await collection.add({
      name,
      contact,
      content,
      type,
      create_date: Date.now()
    });

    return {
      code: 200,
      message: '反馈提交成功',
      data: result
    };
  } catch (err) {
    return {
      code: 500,
      message: '服务器错误，请稍后重试',
      error: err
    };
  }
}; 